<?php
require_once("/home/bluecbhv/Jcuhelpers-WebTech/Google_Custom_Search/Algorithms/Search_Results_Filter.php");

/***********************************************
	This class would retrieve data from an
	array.
************************************************/
class ArrayDataRetriever extends SearchResultsFilter {
	private $title = NULL;
	private $link = NULL;
	private $domain = NULL;
	private $keywords = NULL;
	private $image = NULL;
	
	private $toStore = NULL;
	
	private $phpArrayValuesToInsert = NULL;
	private $phpArray = NULL;
	
	/************************************************************/
	
	function __construct() {
		$this->phpArray = array();
	}
	
	/************************************************************/
	
	function retrieveArrayData($decodedJSONData) {
		foreach ($decodedJSONData['items'] as $key) {
			if (is_array($key)) {
				$this->title = $key['title'];
				$this->link = $key['link'];
				$this->domain = ucfirst(ltrim($key['displayLink'], "www."));
				
				$this->toStore = parent::explodeTitle($this->title);
				
				if ($this->toStore) {
					$this->keywords = parent::getRelevantKeywords($this->link);
					
					if (isset($this->keywords[1])) {
						$this->image = parent::getImagePath($this-link, $this->domain);
						
						$this->phpArrayValuesToInsert = array(
							"Title" => $this->title,
							"Link" => $this->link,
							"Domain" => $this->domain,
							"Image" => $this->image,
							"Keywords" => $this->keywords
						);
						
						array_push($this->phpArray, $this->phpArrayValuesToInsert);
					} else {
						continue;
					}
				}
			}
		}
		
		return $this->phpArray;
	}
}
?>